import { AnyObject } from "antd/es/_util/type";

/**
 * 设置localStorage内容
 */
export function setLocalStorage(key: string, value: string) {
  localStorage.setItem(key, JSON.stringify(value));
}
/**
 *
 * @param o 判断o是否为空
 * @returns
 */
export function isEmpty(o) {
  return o === undefined || o === "" || o === null;
}
/**
 * 获取localStorage内容
 */
export function getLocalStorage(key: string) {
  return isEmpty(localStorage.getItem(key))
    ? localStorage.getItem(key)
    : JSON.parse(localStorage.getItem(key) || `{}`);
}

/**
 * @description 对象键值转对象数组
 *
 */
export function objToArr(obj: AnyObject) {
  return Object.entries(obj).map(([key, value]) => {
    const targetKey = isNaN(Number(key)) ? key : Number(key);
    return { key: targetKey, value };
  });
}
